<?php
/*
	插件链接选择页面
*/
defined('BY_JYA') or exit('error');
//系统链接获取接口
$return=array();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'插件页面'),
	array('op'=>'goodslist','title'=>'商品页面'),
	array('op'=>'grassgrouplist','title'=>'种草分类'),
	array('op'=>'grasslist','title'=>'种草页面'),
	array('op'=>'videogrouplist','title'=>'短视频分类'),
	array('op'=>'videolist','title'=>'短视频页面'),
	array('op'=>'helpgrouplist','title'=>'文章分类页面'),
	array('op'=>'helplist','title'=>'文章页面'),
	array('op'=>'system','plugin'=>'core','action'=>'tools.link','title'=>'系统页面链接'),
);
if($_RQ['op']=='list'){
	$return['list']=array(
		array('title'=>'商城首页','url'=>'jy_weishop/index//current_plugin=jy_weishop'),
		array('title'=>'商品列表','url'=>'jy_weishop/goods.index/'),
		array('title'=>'分类列表','url'=>'jy_weishop/shop.groups/'),
		array('title'=>'购物车','url'=>'jy_weishop/member.cart/'),
		array('title'=>'会员中心','url'=>'jy_weishop/member.index/'),
		array('title'=>'订单入口','url'=>'jy_weishop/order.list/'),
		array('title'=>'优惠券入口','url'=>'jy_weishop/coupon.index/'),
		array('title'=>'我的礼品入口','url'=>'jy_weishop/sale.mylibao/'),
		array('title'=>'短视频入口','url'=>'jy_weishop/video.index/'),
		array('title'=>'种草文章入口','url'=>'jy_weishop/grass.index/'),
		array('title'=>'小程序直播入口','url'=>'jy_weishop/sale.live_index/'),
		array('title'=>'我的直播间','url'=>'jy_weishop/sale.live_myrooms/'),
		array('title'=>'新品上线','img'=>'../addons/jy_weishop/resource/images/new_icon.png','url'=>'jy_weishop/activity//order=new'),
		array('title'=>'今日特价','img'=>'../addons/jy_weishop/resource/images/tejia.png','url'=>'jy_weishop/activity//order=sale_offer'),
		array('title'=>'限时预售','img'=>'../addons/jy_weishop/resource/images/yushou2.png','url'=>'jy_weishop/activity//order=sale_presell'),
		array('title'=>'限时促销','img'=>'../addons/jy_weishop/resource/images/cuxiao.png','url'=>'jy_weishop/activity//order=sale_cuxiao'),
		array('title'=>'限时卖','img'=>'../addons/jy_weishop/resource/images/xianshi.png','url'=>'jy_weishop/activity//order=sale_limit'),
		array('title'=>'新人专享','img'=>'../addons/jy_weishop/resource/images/sale_new.png','url'=>'jy_weishop/activity//order=sale_new'),
	);
	$p_group=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>'1','parentid'=>'0'),'','paixu asc');
	foreach($p_group as $item){
		$return['list'][]=array('title'=>$item['title'],'url'=>'jy_weishop/goods.index//pid='.$item['id']);
	}
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'pagelist'=>false,'list'=>array(
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'url','title'=>'链接地址','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='goodslist'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['status']='1';
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','paixu','title','image','price','status','createtime','total','salenum','unit','saletype');
	$list=pdo_getslice('jy_weishop_goods',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['url']='jy_weishop/goods.detail//id='.$item['id'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'pagelist'=>false,'list'=>array(
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'image','title'=>'图片','type'=>'image'),
			array('name'=>'price','title'=>'价格','type'=>'string'),
			array('name'=>'url','title'=>'短地址','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);	
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='grassgrouplist'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_weishop_grass_group',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['url']='jy_weishop/grass.index//group_id='.$item['id'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'pagelist'=>false,'list'=>array(
			array('name'=>'title','title'=>'分类标题','type'=>'string'),
			array('name'=>'url','title'=>'链接地址','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='grasslist'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_weishop_grass',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['desc'] = $item['desc'] ? $item['desc'] : cfc('tools')->substr($item['content'],0,36);
			$item['createtime']=date('y/m/d H:i:s',$item['createtime']);
			$item['readnum']=pdo_count('jy_weishop_grass_looklist',array('oid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'id');
			$item['likenum']=pdo_count('jy_weishop_grass_like',array('oid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'id');
			$item['url']='jy_weishop/grass.detail//id='.$item['id'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'pagelist'=>false,'list'=>array(
			array('name'=>'title','title'=>'文章标题','type'=>'string'),
			array('name'=>'fenlei','title'=>'文章分类','type'=>'select','options'=>'fenlei'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
			array('name'=>'readnum','title'=>'阅读量','type'=>'string'),
			array('name'=>'likenum','title'=>'点赞量','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['fenlei']=pdo_getall('jy_weishop_grass_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='videogrouplist'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_weishop_video_group',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['url']='jy_weishop/video.index//group_id='.$item['id'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'pagelist'=>false,'list'=>array(
			array('name'=>'title','title'=>'分类标题','type'=>'string'),
			array('name'=>'url','title'=>'链接地址','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='videolist'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_weishop_video',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['desc'] = $item['desc'] ? $item['desc'] : cfc('tools')->substr($item['content'],0,36);
			$item['createtime']=date('y/m/d H:i:s',$item['createtime']);		
			$item['readnum']=pdo_count('jy_weishop_video_looklist',array('oid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'id');
			$item['likenum']=pdo_count('jy_weishop_video_like',array('oid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'id');
			$item['url']='jy_weishop/video.detail//id='.$item['id'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'pagelist'=>false,'list'=>array(
			array('name'=>'title','title'=>'视频标题','type'=>'string'),
			array('name'=>'fenlei','title'=>'视频分类','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
			array('name'=>'readnum','title'=>'阅读量','type'=>'string'),
			array('name'=>'likenum','title'=>'点赞量','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['fenlei']=pdo_getall('jy_weishop_video_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='helpgrouplist'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('core_account_article_fenlei',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['url']='core/article.list//group_id='.$item['id'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'pagelist'=>false,'list'=>array(
			array('name'=>'title','title'=>'分类标题','type'=>'string'),
			array('name'=>'url','title'=>'链接地址','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='helplist'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('core_account_article',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['content'] = strip_tags(str_replace('&nbsp;','',$item['content']));
			$item['desc'] = $item['desc'] ? $item['desc'] : cfc('tools')->substr($item['content'],0,36);
			$item['createtime']=date('y/m/d H:i:s',$item['createtime']);
			$item['edit']=array('op'=>'edit','action'=>'account.article','query'=>'id='.$item['id']);
			$item['url']='core/article.list/detail/id='.$item['id'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'pagelist'=>false,'list'=>array(
			array('name'=>'title','title'=>'文章标题','type'=>'string'),
			array('name'=>'fenlei','title'=>'文章分类','type'=>'string'),
			array('name'=>'keyword','title'=>'关键字','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
			array('name'=>'readnum','title'=>'阅读量','type'=>'string'),
			array('name'=>'likenum','title'=>'点赞量','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['fenlei']=pdo_getall('core_account_article_fenlei',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['htmls']=$htmls;
	exi($return);
}